package com.mxpio.erp.equipment.controller;

import com.mxpio.erp.common.equipment.entity.EquipmentCheckCategory;
import com.mxpio.erp.common.equipment.service.EquipmentCheckCategoryService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 点检类别
 * @Author: wxy
 * @Date:   2021-09-15
 * @Version: V1.0
 */
@Tag(name = "EquipmentCheckCategoryController", description = "点检类别")
@RestController
@RequestMapping("/erp/equipment/spotcheck/tpmCheckCategory")
@Slf4j
public class EquipmentCheckCategoryController {

	@Autowired
	private EquipmentCheckCategoryService equipmentCheckCategoryService;



	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param criteria
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value = "/page")
    @Operation(summary = "点检类别-分页列表查询", description = "点检类别-分页列表查询", method = "GET")
	public Result<?> queryPageList(@Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo,
                                   @Parameter(description="查询参数") Criteria criteria) {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<EquipmentCheckCategory> pageList = equipmentCheckCategoryService.listPage(EquipmentCheckCategory.class,page, criteria);
		return Result.OK(pageList);
	}

     @GetMapping("/list")
     @Operation(summary = "点检类别-无分页列表查询", description = "获取点检类别", method = "GET")
     public Result<List<EquipmentCheckCategory>> list(Criteria criteria) throws UnsupportedEncodingException {
         List<EquipmentCheckCategory> tos = equipmentCheckCategoryService.list(EquipmentCheckCategory.class, criteria);
         return Result.OK(tos);
     }

	/**
     *   添加
     * @param equipmentCheckCategory
     * @return
     */
    @Operation(summary = "点检类别-添加", description = "点检类别-添加", method = "POST")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody EquipmentCheckCategory equipmentCheckCategory) {
        equipmentCheckCategoryService.save(equipmentCheckCategory);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     * @param equipmentCheckCategory
     * @return
     */
    @PutMapping(value = "/edit")
    @Operation(summary = "点检类别-编辑", description = "点检类别-编辑", method = "PUT")
    public Result<?> edit(@RequestBody EquipmentCheckCategory equipmentCheckCategory) {
        equipmentCheckCategoryService.update(equipmentCheckCategory);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete/{id}")
    @Operation(summary = "点检类别-通过id删除", description = "点检类别-通过id删除", method = "DELETE")
    public Result<?> delete(@PathVariable(name="id",required=true) String id) {
        equipmentCheckCategoryService.delMain(id);
        return Result.OK();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Operation(summary = "点检类别-批量删除", description = "点检类别-批量删除", method = "DELETE")
    @DeleteMapping(value = "/deleteBatch/{ids}")
    public Result<?> deleteBatch(@PathVariable(name="ids",required=true) String ids) {
        equipmentCheckCategoryService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK();
    }

//    /**
//     * 导出
//     * @return
//     */
//    @RequestMapping(value = "/exportXls")
//    @Operation(summary = "点检类别-导出", description = "点检类别-导出", method = "GET")
//    public ModelAndView exportXls(HttpServletRequest request, EquipmentCheckCategory equipmentCheckCategory) {
//        return super.exportXls(request, equipmentCheckCategory, EquipmentCheckCategory.class, "点检类别");
//    }
//
//    /**
//     * 导入
//     * @return
//     */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    @Operation(summary = "点检类别-导入", description = "点检类别-导入", method = "POST")
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, TpmCheckCategory.class);
//    }
	/*---------------------------------主表处理-end-------------------------------------*/

}
